package adaoters;

import example.demo_navi.R;
import gui_View.UrlImageView;

import java.util.List;

import models.Video;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class VideosAdapter extends BaseAdapter {
	
	List<Video> videos;

	private LayoutInflater mInflater;
	
	public VideosAdapter(Context context, List<Video> videos) {
		this.videos = videos;
		this.mInflater = LayoutInflater.from(context);
	}


	public int getCount() {
		return videos.size();
	}


	public Object getItem(int position) {
		return videos.get(position);
	}


	public long getItemId(int position) {
		return position;
	}


	public View getView(int position, View convertView, ViewGroup parent) {
		
		if(convertView == null){
		
			convertView = mInflater.inflate(R.layout.list_item_user_video, null);
		}
		
		UrlImageView thumb = (UrlImageView) convertView.findViewById(R.id.userVideoThumbImageView);
		
		TextView title = (TextView) convertView.findViewById(R.id.userVideoTitleTextView); 

		final Video video = videos.get(position);
	
		thumb.setImageDrawable(video.getThumbUrl());
	
		title.setText(video.getTitle());
		
		return convertView;
	}
}